package edu.gatech.oad.mule;

import edu.gatech.oad.mule.config.interfaces._ConfigurationPanel;
import edu.gatech.oad.mule.model.GameStateMachine.GameState;
import edu.gatech.oad.mule.view.interfaces.RenderableBuilding;

/**
 * This class represents the MULE stable.  The MULE stable is a special 
 * building where the Player can purchase MULEs.
 *
 * @author Brendan McGarry, Dale Avery, D'Miria Collins, Natasha Parekh, Jaemin Park
 * @version %I%, %G%
 */
public class MULEStable extends Zone implements RenderableBuilding{
	
	//cost of a MULE (in money)
	public static final int MULE_COST = 100;

	//number of MULEs in stock here (14 for standard/tournament)
	private int MULECount = 14;

	/**
	 * This constructor creates a new MULE stable.  It just
	 * passes everything up to zone
	 *
	 * @param x The x coordinate of the MULE stable
	 * @param y The y coordinate of the MULE stable
	 * @param width The width of the MULE stable
	 * @param height The height of the MULE stable
	 */
	//TODO delete this after JUnit test cases
	public MULEStable(int x, int y, int width, int height){
		super(x, y, width, height);
		MULECount=14;
	}//end constructor
	
	public MULEStable(int x, int y, int width, int height, _ConfigurationPanel cp){
		super(x, y, width, height);
		//if the difficulty is beginner, we start with 25 MULEs instead of 14
		if(cp.getDifficulty().equals("Beginner")){
			MULECount = 25;
		}//end if
	}//end constructor

	/**
	 * This method adds another MULE to the MULE stable
	 */
	public void addMULE(){
		MULECount++;
	}//end method addMULE

	/**
	 * @return The number of MULEs that are in stock
	 */
	public int getMULECount(){
		return MULECount;
	}//end method getMULECount
	
	public void setMULECount(int x){
		MULECount=x;
	}

	@Override
	public void interact(Player p, GameState phase, int round, int time){
		System.out.print(p.getName() + " enters the MULE stable with [" + p.getMoney() + "]. ");
		//check there are still mule's in the stable
		if(MULECount > 0){
			//check player has sufficient credits to
			//  pay for this MULE
			if(p.getMoney() >= MULE_COST){
				//make sure the player doesn't already
				//  have a MULE in his/her inventory
				if(p.getMULE() == null){
					//give the player a MULE
					p.setMULE(new MULE());
					//subtract from the count
					MULECount--;
					//subtract the funds from the player
					p.addMoney(MULE_COST * -1);
					System.out.print(p.getName() + " spent [" + MULE_COST + "] on MULE. ");
				}//end if
				else{
					System.out.print(p.getName() + " already has MULE. ");
				}//end else
			}//end if
			else{
				System.out.print(p.getName() + " has insufficient funds. ");
			}//end else
		}//end if
		else{
			System.out.print("No MULEs remaining. ");
		}//end else
		System.out.println(p.getName() + " leaves with a balance of [" + p.getMoney() + "]");
	}//end method interact
	
	//====================
	//	RenderableBuilding
	//====================
	
	@Override
	public BuildingType getBuildingType(){
		return BuildingType.STABLE;
	}//end method getBuildingType
	
	@Override
	public int getCost(){
		return MULE_COST;
	}//end method getCost

}//end class MULEStable

